﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 基于WPF的电缆采样数据分析系统.Models.CommonUse;
using 基于WPF的电缆采样数据分析系统.Service;
using 基于WPF的电缆采样数据分析系统.Tools.LangugeTool;

namespace 基于WPF的电缆采样数据分析系统.ViewModels.TDRWork
{
    public class ChannelStatusUCViewModel : BindableBase, IDialogHostAware
    {
        // 主机名
        private const string DialogHostName = "RootDialog";

        #region 确定
        /// <summary>
        /// 确定命令
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }

        /// <summary>
        /// 确定方法
        /// </summary>
        private void SaveFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
        }
        #endregion


        #region 取消
        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }

        /// <summary>
        /// 取消方法
        /// </summary>
        private void CancelFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
        }
        #endregion


        /// <summary>
        /// 打开过程中
        /// </summary>
        /// <param name="parameters"></param>
        public void OnDialogOpening(IDialogParameters parameters)
        {
            var channelStatuseList = parameters.GetValue<List<ChannelStatus>>("ChannelStatusList");

            // 通道一
            if (channelStatuseList[0].IsImportWav == 1)
            {
                ChannelTypeOne = LangugeConvertor.GetValue("HaveBeenImported");
                string[] newStr = channelStatuseList[0].FilePath.Split("\\");
                FilePathOne = newStr[newStr.Length - 1];
            } 
            else if (channelStatuseList[0].IsImportWav == 0)
            {
                ChannelTypeOne = LangugeConvertor.GetValue("NotImported");
                FilePathOne = "";
            }

            // 通道二
            if (channelStatuseList[1].IsImportWav == 1)
            {
                ChannelTypeTwo = LangugeConvertor.GetValue("HaveBeenImported");
                string[] newStr = channelStatuseList[1].FilePath.Split("\\");
                FilePathTwo = newStr[newStr.Length - 1];
            }
            else if (channelStatuseList[1].IsImportWav == 0)
            {
                ChannelTypeTwo = LangugeConvertor.GetValue("NotImported");
                FilePathTwo = "";
            }

            // 通道三
            if (channelStatuseList[2].IsImportWav == 1)
            {
                ChannelTypeThree = LangugeConvertor.GetValue("HaveBeenImported");
                string[] newStr = channelStatuseList[2].FilePath.Split("\\");
                FilePathThree = newStr[newStr.Length - 1];
            }
            else if (channelStatuseList[2].IsImportWav == 0)
            {
                ChannelTypeThree = LangugeConvertor.GetValue("NotImported");
                FilePathThree = "";
            }
        }

        /// <summary>
        /// 构造器
        /// </summary>
        public ChannelStatusUCViewModel()
        {
            //绑定确定和取消命令
            SaveCommand = new DelegateCommand(SaveFun);
            CancelCommand = new DelegateCommand(CancelFun);
        }


        #region 通道一
        /// <summary>
        /// 通道状态(通道一)
        /// </summary>
        private string _ChannelTypeOne;

        /// <summary>
        /// 通道状态(通道一)
        /// </summary>
        public string ChannelTypeOne
        {
            get { return _ChannelTypeOne; }
            set {
                _ChannelTypeOne = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 路径(通道一)
        /// </summary>
        private string _FilePathOne;

        /// <summary>
        /// 路径(通道一)
        /// </summary>
        public string FilePathOne
        {
            get { return _FilePathOne; }
            set { 
                _FilePathOne = value;
                RaisePropertyChanged();
            }
        }

        #endregion


        #region 通道二

        /// <summary>
        /// 通道状态(通道二)
        /// </summary>
        private string _ChannelTypeTwo;

        /// <summary>
        /// 通道状态(通道二)
        /// </summary>
        public string ChannelTypeTwo
        {
            get { return _ChannelTypeTwo; }
            set
            {
                _ChannelTypeTwo = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 路径(通道二)
        /// </summary>
        private string _FilePathTwo;

        /// <summary>
        /// 路径(通道二)
        /// </summary>
        public string FilePathTwo
        {
            get { return _FilePathTwo; }
            set
            {
                _FilePathTwo = value;
                RaisePropertyChanged();
            }
        }

        #endregion


        #region 通道三
        /// <summary>
        /// 通道状态(通道三)
        /// </summary>
        private string _ChannelTypeThree;

        /// <summary>
        /// 通道状态(通道三)
        /// </summary>
        public string ChannelTypeThree
        {
            get { return _ChannelTypeThree; }
            set
            {
                _ChannelTypeThree = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 路径(通道三)
        /// </summary>
        private string _FilePathThree;

        /// <summary>
        /// 路径(通道三)
        /// </summary>
        public string FilePathThree
        {
            get { return _FilePathThree; }
            set
            {
                _FilePathThree = value;
                RaisePropertyChanged();
            }
        }

        #endregion
    }
}
